package com.icexxx.ice_notepad;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

public class PanelManager {

    public static JPanel createMainPanel() {
        JPanel jpanel = new JPanel();
        jpanel.add(createJTabbedPane());
        jpanel.setBackground(Color.LIGHT_GRAY);
        jpanel.setLayout(new GridLayout(1, 1));
        return jpanel;
    }

    private static Component createJTabbedPane() {
        JTabbedPane jTabbedPane = new JTabbedPane();
        jTabbedPane.addTab("sql", createSqlPanel("sql"));
        jTabbedPane.addTab("data", createDataPanel("data"));
        jTabbedPane.addTab("code", createCodePanel("code"));
        jTabbedPane.addTab("config", createConfigPanel("config"));
        jTabbedPane.addTab("log", createLogPanel("log"));
        jTabbedPane.addTab("日报", createReportPanel("日报"));
        jTabbedPane.addTab("temp", createTempPanel("temp"));
        jTabbedPane.addTab("剪切板", createClipboardPanel("剪切板"));
        jTabbedPane.addTab("other1", createOther1Panel("other1"));
        jTabbedPane.addTab("other2", createOther2Panel("other2"));
        jTabbedPane.addTab("other3", createOther3Panel("other3"));
        jTabbedPane.addTab("other4", createOther4Panel("other4"));
        jTabbedPane.addTab("other5", createOther5Panel("other5"));
        jTabbedPane.addTab("other6", createOther6Panel("other6"));
        jTabbedPane.addTab("other7", createOther7Panel("other7"));
        jTabbedPane.addTab("other8", createOther8Panel("other8"));
        jTabbedPane.addTab("other9", createOther9Panel("other9"));
        jTabbedPane.addTab("other10", createOther10Panel("other10"));
        return jTabbedPane;
    }

    private static JPanel createContentPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setLayout(new BorderLayout());
        JTextArea jTextArea = createJTextArea();
        JPanel toolBarPanel = createToolBarPanelPanel(jTextArea, title);
        jpanel.add(toolBarPanel, BorderLayout.NORTH);
        jpanel.add(jTextArea, BorderLayout.CENTER);
        return jpanel;
    }

    private static JPanel createToolBarPanelPanel(JTextArea jTextArea, String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(Color.LIGHT_GRAY);
        jpanel.setLayout(new FlowLayout());
        jpanel.add(ButtonManager.createPasteButton(jTextArea));//
        jpanel.add(ButtonManager.createCopyButton(jTextArea));
        jpanel.add(ButtonManager.createEmptyButton(jTextArea));
        jpanel.add(ButtonManager.createSaveButton(jTextArea, title));
        jpanel.add(ButtonManager.createLoadButton(jTextArea, title));
        return jpanel;
    }

    private static JTextArea createJTextArea() {
        JTextArea jTextArea = new JTextArea();
        MouseListener mouseListener = new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("aaaaa");
            }
        };
        Dimension preferredSize = new Dimension(1470, 790);
        jTextArea.setPreferredSize(preferredSize);
        jTextArea.addMouseListener(mouseListener);
        return jTextArea;
    }

    private static Component createSqlPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(0, 255, 127));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createDataPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 127, 255));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createCodePanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(255, 127, 0));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createConfigPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(0, 0, 127));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createLogPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(0, 255, 255));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createReportPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 255, 0));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createTempPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(255, 127, 127));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createClipboardPanel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(0, 0, 255));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther1Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 0, 0));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther2Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 255, 127));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther3Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(255, 127, 255));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther4Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(0, 127, 0));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther5Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 0, 127));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther6Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 255, 255));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther7Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(255, 255, 0));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther8Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(0, 127, 127));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther9Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(127, 0, 255));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

    private static Component createOther10Panel(String title) {
        JPanel jpanel = new JPanel();
        jpanel.setBackground(new Color(255, 0, 0));
        jpanel.add(createContentPanel(title));
        return jpanel;
    }

}
